<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class StaffOrder
 * @package App\Models
 * @version December 6, 2018, 7:18 pm CST
 *
 * @property integer oid
 * @property integer staff_id
 * @property string staff_name
 * @property integer card_id
 * @property string card_name
 * @property boolean card_type
 * @property string card_date
 * @property string order_no
 * @property string vpl_number
 * @property string id_no
 * @property string mobile
 * @property integer amount
 * @property integer valid_time_start
 * @property integer valid_time_end
 * @property boolean status
 */
class StaffOrder extends Model
{
    use SoftDeletes;

    public $table = 'staff_order';
    
    const CREATED_AT = 'created_at';
    const UPDATED_AT = 'updated_at';


    protected $dates = ['deleted_at'];

    protected $appends = ['orgs']; 

    public $fillable = [
        'oid',
        'staff_id',
        'staff_name',
        'card_id',
        'card_name',
        'card_type',
        'card_date',
        'order_no',
        'vpl_number',
        'id_no',
        'mobile',
        'amount',
        'valid_time_start',
        'valid_time_end',
        'status'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'integer',
        'oid' => 'integer',
        'staff_id' => 'integer',
        'staff_name' => 'string',
        'card_id' => 'integer',
        'card_name' => 'string',
        'card_type' => 'integer',
        'card_date' => 'string',
        'order_no' => 'string',
        'vpl_number' => 'string',
        'id_no' => 'string',
        'mobile' => 'string',
        'amount' => 'integer',
        'valid_time_start' => 'integer',
        'valid_time_end' => 'integer',
        'status' => 'integer'
    ];
    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [

    ];



    /**
     * 获取组织结构树
     *
     * @param  string $value
     * @return void
     */
    public function getOrgsAttribute() {
        return $this->attributes['orgs'] = StaffOrg::getNodes($this->attributes['oid']);
    }
    
}
